<template>
	<view class="padding-top">
		<form class="" @submit="formSubmit">
			<view class="card-menu cu-list menu">
				<view class="cu-form-group ">
					<view class="title">姓名<text class="text-red">*</text></view>
					<input placeholder="填写姓名" name="name" v-model="userinfo.name"></input>
					<!-- <button class='cu-btn bg-green shadow'>上传识别</button> -->
				</view>
				<view class="cu-form-group">
					<view class="title">居住信息<text class="text-red">*</text></view>
					<input placeholder="如XX栋XXX室" name="juzhu" v-model="userinfo.address"></input>
				</view>
				<view class="cu-form-group">
					<view class="title">小区身份</view>
					<picker @change="PickerChange2" :value="index2" :range="picker2" name="shenfen">
						<view class="picker">
							{{index2>-1?picker2[index2]:'点击选择'}}
						</view>
					</picker>
				</view>
				<view class="cu-form-group">
					<view class="title">车牌号</view>
					<input placeholder="请输入车牌号" v-model="userinfo.car" name="carnumber"></input>
				</view>
				<view class="cu-form-group">
					<view class="title">手机号码<text class="text-red">*</text></view>
					<input placeholder="请输入手机号码" name="phonenumber" v-model="userinfo.phone"></input>
					<view class="cu-capsule radius">
						<view class='cu-tag bg-blue '>
							+86
						</view>
						<view class="cu-tag line-blue">
							中国大陆
						</view>
					</view>
				</view>
				<radio-group class="block" name="isbendi">
					<view class="cu-form-group">
						<view class="title">是否健康</view>
						<view>
							<radio class='blue radio margin-left-sm' checked="true" value="0" /><text class="padding-left-xs">是</text>
							<radio class='blue radio' value="1" /><text class="padding-left-xs">否</text>
							
						</view>
					</view>
				</radio-group>
				<radio-group class="block" name="ishubei">
					<view class="cu-form-group">
						<view class="title">有无重点疫区旅居接触</view>
						<view>
							<radio class='blue radio' value="1" /><text class="padding-left-xs">是</text>
							<radio class='blue radio margin-left-sm' checked="true" value="0" /><text class="padding-left-xs">否</text>
						</view>
					</view>
				</radio-group>
				<view class="cu-form-group ">
					<button class="cu-btn bg-blue shadow" form-type="submit">提交信息</button>
				</view>
			</view>
			
		</form>
	</view>
</template>

<script>
	import {post,get,showModal} from '../../utils/index.js';
	var that;
	export default {
		data() {
			return {
				bendi:false,
				index:-1,
				picker: ['春节在家未出行', '自驾出行','大巴汽车', '铁路火车','飞机出行'],
				index2:-1,
				picker2: ['租户', '业主', '访客'],
				shequ_id:'',
				shequ_name:'',
				shequ_type:'',
				userinfo:{}
			}
		},
		onLoad(e) {
			that = this;

			post(that.weixin_app + '/wxapp/get_userInfo', {
				uid: uni.getStorageSync('uid')
			}).then(res => {
				that.userinfo = res.data;
				that.index2 = res.data.shenfenid;
				//console.log(res.data)
			});
			
		},
		// onShow: function() {
			
		// 	wx.checkSession({ //检测当前用户的session_key是否过期
		// 		success: function() { //session_key 未过期，并且在本生命周期一直有效
		// 			//console.log("授权未过期")
					
		// 		},
		// 		fail: function() { //session_key 已经失效，需要重新执行登录流程
		// 			//console.log("授权过期")
		// 			wx.navigateTo({
		// 				url: "/pages/auth/auth" //重新授权
		// 			})
		// 			uni.setStorageSync("toadd",1);
		// 		}
		// 	})
		// },
		methods: {
			formSubmit(e){
				that = this;
				//console.log(e)
				let params = e.detail.value;
				if(params.name.length == 0){
					showModal('温馨提示','请填姓名');
					return false;
				}
				if(params.juzhu.length == 0){
					showModal('温馨提示','请填写居住信息');
					return false;
				}
				if(this.index2 === -1){
					showModal('温馨提示','请选择身份后再提交');
					return false;
				}
				if(params.phonenumber.length == 0){
					showModal('温馨提示','请填写手机号');
					return false;
				}
				params.shenfen = this.picker2[this.index2];
				params.shenfenid = this.index2;
				params.chuxing = this.picker[this.index];
				params.pid = uni.getStorageSync('pid');
				params.uid = uni.getStorageSync('uid');
				params.shequ_id = this.shequ_id;
				params.shequ_name = this.shequ_name;
				params.shequ_type = this.shequ_type;
				post(that.weixin_app + '/wxapp/upuserinfo',params).then(res=>{
					if(res.data.code === "1"){
						uni.reLaunch({
							url:'../index/index'
						})
					}else{
						showModal('温馨提示','登记失败，请重试')
					}
				});
				//console.log(params);
			},
			PickerChange(e) {
				this.index = e.detail.value
			},
			PickerChange2(e) {
				this.index2 = e.detail.value
			}
		}
	}
</script>

<style>

</style>
